
if PlayerSetting == nil then
	PlayerSetting = RegisterController('player_settings')
	PlayerSetting.__settings = {}
	setmetatable(PlayerSetting,PlayerSetting)
end

local public = PlayerSetting

local m_SettingModel = {
	
	-- 默认接受任务类型
	['accept_quest_type'] = {
		default = 'good',
		option = {'bad','none','good','free'},
	}
}

function CDOTA_BaseNPC_Hero:setting(key)
	return public:get(self:GetSteamID(),key)
end

function public:__call(hero)
	self:GetPlayerSetting(hero:GetSteamID())
end

function public:GetPlayerSetting(steamid)
	local t = self.__settings[steamid]
	if t == nil then
		t = {}
		for k,v in pairs(m_SettingModel) do
			t[k] = v.default
		end
		self.__settings[steamid] = t
		CustomNetTables:SetTableValue("Common", "setting_"..steamid, t )
	end
	return t
end

function public:IsValid(key, value)
	local t = m_SettingModel[key]
	if not t then return false end

	for i,v in ipairs(t.option) do
		if v == value then
			return true
		end
	end

	return false
end

function public:set(steamid, key, value)
	if not self:IsValid(key, value) then return end

	local setting = self:GetPlayerSetting(steamid)
	setting[key] = value

	CustomNetTables:SetTableValue("Common", "setting_"..steamid, setting )
	CustomGameEventManager:Send_ServerToAllClients("avalon_update_player_settings", EmptyTable)
end

function public:get(steamid, key)
	local setting = self:GetPlayerSetting(steamid)
	return setting[key]
end

function public:all(steamid)
	return self:GetPlayerSetting(steamid)
end


function public:SwapWeaponEffect( hero, index )
	if hero.__weapon_effect_particle ~= nil then
		ParticleManager:DestroyParticle(hero.__weapon_effect_particle, true)
	end
	local path = ''
	local name = string.gsub(hero:GetUnitName(), 'npc_dota_hero_', '')
	local attach_name = 'attach_attack1'

	if name == "crystal_maiden" then
		if index == 1 then
			path = 'particles/avalon/weapon/weapon_effect_lingcai.vpcf'
		elseif index == 2 then
			path = 'particles/avalon/weapon/weapon_effect2_lingcai.vpcf'
		else
			path = 'particles/avalon/weapon/weapon_effect3_lingcai.vpcf'
		end
	elseif name == "juggernaut" then
		if index == 1 then
			path = 'particles/avalon/weapon/weapon_effect_tianchen.vpcf'
		elseif index == 2 then
			path = 'particles/avalon/weapon/weapon_effect2_tianchen.vpcf'
		else
			path = 'particles/avalon/weapon/weapon_effect3_tianchen.vpcf'
		end
	elseif name == "phantom_lancer" then
		attach_name = 'attach_weapon_effect'
		if index == 1 then
			path = 'particles/avalon/weapon/weapon_effect_luxiao.vpcf'
		elseif index == 2 then
			path = 'particles/avalon/weapon/weapon_effect2_luxiao.vpcf'
		else
			path = 'particles/avalon/weapon/weapon_effect3_luxiao.vpcf'
		end
	elseif name == "phantom_assassin" then
		if index == 1 then
			path = 'particles/avalon/weapon/weapon_effect_juexin.vpcf'
		elseif index == 2 then
			path = 'particles/avalon/weapon/weapon_effect2_juexin.vpcf'
		else
			path = 'particles/avalon/weapon/weapon_effect3_juexin.vpcf'
		end
	elseif name == "centaur" then
		attach_name = 'attach_weapon_effect'
		if index == 1 then
			path = 'particles/avalon/weapon/weapon_effect_huankong.vpcf'
		elseif index == 2 then
			path = 'particles/avalon/weapon/weapon_effect_huankong2.vpcf'
		else
			path = 'particles/avalon/weapon/weapon_effect_huankong3.vpcf'
		end
	elseif name == "legion_commander" then
		attach_name = 'attach_weapon_effect'
		if index == 1 then
			path = 'particles/avalon/weapon/weapon_effect_moluo2.vpcf'
		elseif index == 2 then
			path = 'particles/avalon/weapon/weapon_effect_moluo3.vpcf'
		else
			path = 'particles/avalon/weapon/weapon_effect_moluo.vpcf'
		end
	elseif name == "slark" then
		if index == 1 then
			path = 'particles/avalon/weapon/weapon_effect_yunlian.vpcf'
		elseif index == 2 then
			path = 'particles/avalon/weapon/weapon_effect2_yunlian.vpcf'
		else
			path = 'particles/avalon/weapon/weapon_effect3_yunlian.vpcf'
		end
	elseif name == "spectre" then
		attach_name = 'attach_weapon_effect'
		if index == 1 then
			path = 'particles/avalon/weapon/weapon_effect_mengyan.vpcf'
		elseif index == 2 then
			path = 'particles/avalon/weapon/weapon_effect2_mengyan.vpcf'
		else
			path = 'particles/avalon/weapon/weapon_effect3_mengyan.vpcf'
		end
	elseif name == "lina" then
		attach_name = 'attach_weapon_effect'
		if index == 1 then
			path = 'particles/avalon/weapon/weapon_effect_humei.vpcf'
		elseif index == 2 then
			path = 'particles/avalon/weapon/weapon_effect2_humei.vpcf'
		else
			path = 'particles/avalon/weapon/weapon_effect3_humei.vpcf'
		end
	elseif name == "templar_assassin" then
		if index == 1 then
			path = 'particles/avalon/weapon/weapon_effect_juexin.vpcf'
		elseif index == 2 then
			path = 'particles/avalon/weapon/weapon_effect2_juexin.vpcf'
		else
			path = 'particles/avalon/weapon/weapon_effect3_juexin.vpcf'
		end
	end

	local e = ParticleManager:CreateParticle(path, PATTACH_CUSTOMORIGIN_FOLLOW, hero)
	ParticleManager:SetParticleControlEnt(e, 0, hero, 5, attach_name, hero:GetAbsOrigin(), false)
	hero.__weapon_effect_particle = e
end